package sample;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * Represents a Wavelet
 * @author ago
 *
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class WaveletRecord {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private String waveId;
  
  @Persistent
  private String title;
  
  @Persistent
  private Integer numParticipants;
  
  @Persistent
  private Date date;

  WaveletRecord(String waveId, String title, Integer numParticipants) {
    this.waveId = waveId;
    this.title = title;
    this.numParticipants = numParticipants;
    this.date = new Date();
  }
  
  public String getWaveId() {
    return waveId;
  }
  
  public String getWaveIdEncoded() {
    try {
      return URLEncoder.encode(waveId, "UTF-8");
    } catch(UnsupportedEncodingException e) {
      return "FATAL ERROR WITH ENCODING";
    }
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public Integer getNumParticipants() {
    return numParticipants;
  }

  public void setNumParticipants(Integer numParticipants) {
    this.numParticipants = numParticipants;
  }

  public Date getDate() {
    return date;
  }

  public void setDate(Date date) {
    this.date = date;
  }
}
